package yanglib.application.metadata.server;

import yanglib.application.metadata.MetadataMembership;
import yanglib.application.metadata.message.MetadataMessageDeserializer;
import yanglib.network.nio.NIONetwork;
import yanglib.network.tcp.TcpNetwork;
import yanglib.test.network.TestMembership;
import yanglib.test.network.TestMessage;
import yanglib.test.network.TestMessageDeserializer;
import yanglib.test.network.TestMessageHandler;

import java.io.File;

/**
 * Created with IntelliJ IDEA.
 * User: user
 * Date: 9/5/14
 * Time: 3:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class MetadataServer {

    private int selfID;

    public MetadataServer(int selfID, String configFile, String logPath){
        this.selfID = selfID;
        MetadataMembership membership = new MetadataMembership(new File(configFile));
        ServerMessageHandler handler = new ServerMessageHandler(selfID, logPath);
        MetadataMessageDeserializer deserializer = new MetadataMessageDeserializer();
        NIONetwork network = new NIONetwork(membership, handler, deserializer, selfID);
        handler.setNetwork(network);
    }

    public static void main(String[] args) throws Exception {
        if(args.length != 3){
            System.out.println("java MetadataServer <id> <configFile> <logPath>");
            return;
        }
        int id = Integer.parseInt(args[0]);
        String configFile = args[1];
        String logPath = args[2];
        MetadataServer server = new MetadataServer(id, configFile, logPath);
        while(true){
            Thread.sleep(60);
        }
    }

}
